/*    */ package com.newcrm.webapi.sub;
/*    */ 
/*    */ import com.newcrm.bean.CompanyInfo;
/*    */ import com.newcrm.bean.User;
/*    */ import com.newcrm.db.GroupManager;
/*    */ import com.newcrm.db.UserManager;
/*    */ import com.newcrm.exception.DBException;
/*    */ import com.newcrm.exception.NotFoundException;
/*    */ import com.newcrm.util.Util;
/*    */ import com.newcrm.webapi.AbstractAction;
/*    */ import com.newcrm.webapi.AbstractHttpServlet;
/*    */ import java.io.IOException;
/*    */ import java.io.PrintWriter;
/*    */ import java.sql.SQLException;
/*    */ import javax.servlet.ServletException;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import net.sf.json.JSONObject;
/*    */ import org.apache.log4j.Logger;
/*    */ 
/*    */ public class DeleteGroup extends AbstractAction
/*    */ {
/* 34 */   private static Logger logger = Logger.getLogger(DeleteGroup.class.getName());
/*    */ 
/* 36 */   private int id = 0;
/*    */ 
/*    */   public DeleteGroup(AbstractHttpServlet servlet) {
/* 39 */     super(servlet);
/*    */   }
/*    */ 
/*    */   public DeleteGroup(AbstractHttpServlet servlet, String id) {
/* 43 */     super(servlet);
/* 44 */     this.id = Util.str2Int(id);
/*    */   }
/*    */ 
/*    */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*    */     throws IOException, ServletException, NotFoundException
/*    */   {
/* 50 */     User user = super.getLoginUser(request);
/*    */ 
/* 52 */     if (!user.isAdmin) {
/* 53 */       super.showErrorMessage(response, "只有管理员才有权限删除部门信息");
/* 54 */       return;
/*    */     }
/*    */ 
/* 57 */     GroupManager manager = new GroupManager();
/* 58 */     int result = manager.delete(this.id);
/* 59 */     if (result <= 0) {
/* 60 */       super.showErrorMessage(response, "删除部门时出错，请稍后再试");
/* 61 */       return;
/*    */     }
/*    */     try
/*    */     {
/* 65 */       CompanyInfo company = super.getCompany(request);
/*    */ 
/* 67 */       company.setGroups(manager.list(user.companyId));
/*    */ 
/* 70 */       UserManager userManager = new UserManager();
/* 71 */       company.users = userManager.getCompanyUsers(user.companyId, null);
/*    */     }
/*    */     catch (DBException e) {
/* 74 */       logger.warn("delete group failed", e);
/* 75 */       super.showErrorMessage(response, "删除部门时出错，请稍后再试");
/* 76 */       return;
/*    */     } catch (SQLException e) {
/* 78 */       logger.warn("delete group failed", e);
/* 79 */       super.showErrorMessage(response, "删除部门时出错，请稍后再试");
/* 80 */       return;
/*    */     }
/*    */ 
/* 83 */     response.setContentType("text/html;charset=utf-8");
/* 84 */     PrintWriter out = response.getWriter();
/* 85 */     JSONObject jsonObject = new JSONObject();
/* 86 */     jsonObject.put("error", "0");
/* 87 */     jsonObject.put("result", Integer.valueOf(result));
/* 88 */     out.println(jsonObject);
/* 89 */     out.flush();
/* 90 */     out.close();
/*    */   }
/*    */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.DeleteGroup
 * JD-Core Version:    0.6.1
 */